namespace Lzfy_Refund_Service.Services
{
    /// <summary>
    /// Redis服务接口
    /// </summary>
    public interface IRedisService
    {
        /// <summary>
        /// 设置键值对，带过期时间
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="expiry">过期时间</param>
        /// <returns>是否设置成功</returns>
        Task<bool> SetAsync(string key, string value, TimeSpan? expiry = null);

        /// <summary>
        /// 获取值
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>值</returns>
        Task<string?> GetAsync(string key);

        /// <summary>
        /// 检查键是否存在
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>是否存在</returns>
        Task<bool> ExistsAsync(string key);

        /// <summary>
        /// 删除键
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>是否删除成功</returns>
        Task<bool> DeleteAsync(string key);

        /// <summary>
        /// 批量检查键是否存在
        /// </summary>
        /// <param name="keys">键列表</param>
        /// <returns>存在的键列表</returns>
        Task<List<string>> BatchExistsAsync(IEnumerable<string> keys);

        /// <summary>
        /// 设置键值对到指定数据库，带过期时间
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="value">值</param>
        /// <param name="database">数据库编号</param>
        /// <param name="expiry">过期时间</param>
        /// <returns>是否设置成功</returns>
        Task<bool> SetAsync(string key, string value, int database, TimeSpan? expiry = null);

        /// <summary>
        /// 从指定数据库获取值
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="database">数据库编号</param>
        /// <returns>值</returns>
        Task<string?> GetAsync(string key, int database);

        /// <summary>
        /// 从指定数据库删除键
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="database">数据库编号</param>
        /// <returns>是否删除成功</returns>
        Task<bool> DeleteAsync(string key, int database);

        /// <summary>
        /// 获取指定数据库中匹配模式的所有键
        /// </summary>
        /// <param name="pattern">匹配模式</param>
        /// <param name="database">数据库编号</param>
        /// <returns>匹配的键列表</returns>
        Task<List<string>> GetKeysAsync(string pattern, int database);

        /// <summary>
        /// 批量检查指定数据库中键是否存在
        /// </summary>
        /// <param name="keys">键列表</param>
        /// <param name="database">数据库编号</param>
        /// <returns>存在的键列表</returns>
        Task<List<string>> BatchExistsAsync(IEnumerable<string> keys, int database);
    }
}